

#include <casgidriver/CASgiDriverE.h>

byte_t CASgiDriver::VBufferIRQ[BUFFER_IRQ_SIZE];
uint16_t CASgiDriver::VReadIndex=0;
uint16_t CASgiDriver::VWriteIndex=0;
uint32_t CASgiDriver::VBytesWritten=0;

		// ******************* Aux IRQ Handler **************

void 	CASgiDriver::FReadByteHandler(void){

	VBufferIRQ[VWriteIndex] = sgi_uart_getchar();
	VWriteIndex++;
	VWriteIndex%= BUFFER_IRQ_SIZE;
	VBytesWritten++;
	/**
	 * TODO:chequear si puede darle tiempo a llegar a este valor sin
	 * vaciar bytes desde la transición, aunque no creo
	 */
//	EDROOMEventIRQ2.Signal();

}




	// ******************* CONSTRUCTOR ************************************



CASgiDriver::CASgiDriver(const char * const roomname,TEDROOMComponentID id, unsigned int roomNumMaxMens, TEDROOMPriority roomtaskPrio, TEDROOMStackSizeType roomStack, CEDROOMMemory *pActorMemory ) : 
		CEDROOMComponent(roomname,id,EDROOMprioMINIMUM+1,0,roomNumMaxMens,roomtaskPrio,roomStack, pActorMemory )




		// ***************	Estado Top *****************

		,edroomTopState(*this,pActorMemory)


{


}


	//***************	METODOS PUBLICOS  ********************************



		//**********           CONFIGURACION               ************


int CASgiDriver::EDROOMConfig() {




 return 0; }



		//**********           START               ************


int CASgiDriver::EDROOMStart() {



		//****************** INICIO DEL PROPIO ACTOR **********************

	CEDROOMComponent::EDROOMStart(); 	// Llamada a la funcion Start de la clase Actor

return 0;}


	// ***************	METODOS PROTEGIDOS *******************************



		//**********        COMPORTAMIENTO           ************



void CASgiDriver::EDROOMBehaviour() {

	edroomTopState.EDROOMBehaviour();

}




		//**********        ACTORTERMINADO           ************


	#ifdef _EDROOM_SYSTEM_CLOSE

TEDROOMBool CASgiDriver::EDROOMIsComponentFinished() {


	return ( CEDROOMComponent::EDROOMIsComponentFinished());

}


	#endif

	// ***************	EDROOM Memory ******************************

void CASgiDriver::CEDROOMMemory::SetMemory(TEDROOMUInt32 numMessages_, CEDROOMMessage * MessagesMem_, TEDROOMBool * MessagesMemMarks_, CEDROOMQueue::CQueueNode * QueueNodesMem_, TEDROOMBool * QueueNodesMemMarks_){
		CEDROOMComponentMemory::SetMemory( numMessages_,MessagesMem_, MessagesMemMarks_, QueueNodesMem_, QueueNodesMemMarks_, QueueHeads);


}

